/**
 * 文件复制
 *    复制文件input.txt 变成 input2.txt
 *
 * Q1: 有没有改进的可能性？
 * Q2：如何复制其他类型非文本文件？
 * */

function copyFile(path) {
    var fs = require('fs');
    data='';

    var readStream= fs.createReadStream(path.source);
    var writeStream= fs.createWriteStream(path.target);


    readStream.on('data',function (chunk) { // 5s
        writeStream.write(chunk,'utf-8');
    })

    readStream.on('end',function () { //5s
        /*writeStream.write(data,'utf-8');*/
        writeStream.end();
    })

    writeStream.on('finish',function () {
        console.log('写入成功！');
    })
}


/*var path = {
    source:'./file/input.txt',
    target:'./file/input2.txt'
}*/



module.exports = {
    copyFile
}

